package com.heima.article.feign;

import com.heima.article.service.ApArticleConfigService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.article.service.ApArticleConfigService;
import com.heima.article.service.ApArticleService;
import com.heima.feign.article.IArticleClient;
import com.heima.model.article.dtos.ArticleCommentDto;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.comment.dtos.CommentConfigDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.article.pojos.ApArticleConfig;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmCommentDto;
import com.heima.model.wemedia.dtos.WmStatisticsNewsPageDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author 陈辉
 * @data 2023 11:27
 */
@RestController
public class ArticleClient implements IArticleClient {

    @Autowired
    private ApArticleService apArticleService;
    @Autowired
    private ApArticleConfigService apArticleConfigService;



    @PostMapping("/api/v1/article/save")
    public ResponseResult saveOrUpdate(@RequestBody ArticleDto articleDto) {
        return apArticleService.saveArticle(articleDto);
    }

    /**
     * 查询文章中的点赞跟收藏数
     * @param id
     * @param beginTime
     * @param endTime
     * @return
     */
    @GetMapping("/api/v1/article/queryLikesAndConllections")
    public ResponseResult queryLikesAndConllections(@RequestParam("wmUserId") Integer id
            , @RequestParam("beginDate")Date beginTime
            , @RequestParam("endDate") Date endTime) {
        return apArticleService.queryLikesAndConllections(id,beginTime,endTime);
    }

    /**
     * 分页展示文章列表，展示当前时间范围内的具体文章阅读、评论、收藏的数量。
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/article/newPage")
    public PageResponseResult newPage( @RequestBody WmStatisticsNewsPageDto dto) {
        return apArticleService.newPage(dto);
    }


    /**
     * 查找新闻评论
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/article/findNewsComments")
    @Override
    public PageResponseResult findNewsComments(@RequestBody ArticleCommentDto dto) {
        return apArticleService.findNewsComments(dto);
    }

    /**
     * 查找app文章id，查询文章的配置信息
     * @param articleId
     * @return
     */
    @GetMapping("/api/v1/article/findArticleConfigByArticleId/{articleId}")
    @Override
    public ResponseResult findArticleConfigByArticleId(@PathVariable("articleId") Long articleId) {
        ApArticleConfig apArticleConfig = apArticleConfigService.
                getOne(Wrappers.<ApArticleConfig>lambdaQuery().eq(ApArticleConfig::getArticleId, articleId));
        return ResponseResult.okResult(apArticleConfig);
    }

    /**
     * 查看所有评论
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/api/v1/article/findAllComment")
    public PageResponseResult findAllComment(@RequestBody WmCommentDto dto) {
        return apArticleService.findAllComment(dto);
    }

    /**
     * 修改app配置
     *
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/api/v1/article/updateCommentStatus")
    public ResponseResult updateCommentStatus(@RequestBody CommentConfigDto dto) {
        return apArticleConfigService.updateCommentStatus(dto);
    }
}
